const posthtml = require('posthtml')
const insertScriptToBody = function (tree) {
  tree.match({ tag: 'body' }, (node) => {
    node.content.push({
      tag: 'script',
      attrs: {
        src: './js/index.js',
      },
    })
    return node
  })
}

const insertScriptToHtml = (html) => {
  return posthtml().use(insertScriptToBody).process(html, { sync: true }).html
}
module.exports = {
  insertScriptToHtml,
}
